package com.wc.alorithm_luogu._DFS.走迷宫;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/17 10:01
 * @description https://www.luogu.com.cn/problem/P1238
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 15;
    static int[][] g = new int[N][N];
    static int[] path = new int[N * N];
    static boolean[] st = new boolean[N * N];
    static int n, m, sx, sy, ex, ey;
    static int[] dx = new int[]{0, -1, 0, 1}, dy = new int[]{-1, 0, 1, 0};
    static boolean hasSuccess = false;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                g[i][j] = sc.nextInt();
            }
        }
        sx = sc.nextInt() - 1;
        sy = sc.nextInt() - 1;
        ex = sc.nextInt() - 1;
        ey = sc.nextInt() - 1;
        dfs(1, sx, sy, path);
        if (!hasSuccess) out.println(-1);
        out.flush();
    }

    static void dfs(int u, int x, int y, int[] path) {
        path[u] = x * m + y;
        if (x == ex && y == ey) {
            out.printf("(%d,%d)", path[1] / m + 1, path[1] % m + 1);
            for (int i = 2; i <= u; i++) {
                out.printf("->(%d,%d)", path[i] / m + 1, path[i] % m + 1);
            }
            out.println();
            hasSuccess = true;
            return;
        }
        st[x * m + y] = true;
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx >= 0 && nx < n && ny >= 0 && ny < m && !st[nx * m + ny] && g[nx][ny] == 1) {
                dfs(u + 1, nx, ny, path);
            }
        }

        st[x * m + y] = false;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
